<?php

class Member { 
	private $id;
	private $username;
	private $password;
	private $group;
	private $nickname;
	private $email;
	private $regdate;
	private $root=2;
	private $qq;
	
	/**
	 * @return unknown
	 */
	public function getQq() {
		return $this->qq;
	}
	
	/**
	 * @param unknown_type $qq
	 */
	public function setQq($qq) {
		$this->qq = $qq;
	}
	/**
	 * @return unknown
	 */
	public function getEmail() {
		return $this->email;
	}
	
	/**
	 * @return unknown
	 */
	public function getGroup() {
		return $this->group;
	}
	
	/**
	 * @return unknown
	 */
	public function getId() {
		return $this->id;
	}
	
	/**
	 * @return unknown
	 */
	public function getNickname() {
		return $this->nickname;
	}
	
	/**
	 * @return unknown
	 */
	public function getPassword() {
		return $this->password;
	}
	
	/**
	 * @return unknown
	 */
	public function getRegdate() {
		return $this->regdate;
	}
	
	/**
	 * @return unknown
	 */
	public function getRoot() {
		return intval($this->root);
	}
	
	/**
	 * @return unknown
	 */
	public function getUsername() {
		return $this->username;
	}
	
	/**
	 * @param unknown_type $email
	 */
	public function setEmail($email) {
		$this->email = $email;
	}
	
	/**
	 * @param unknown_type $group
	 */
	public function setGroup($group) {
		App::loadMod("Group");
		$this->group = new Group($this->jieku);
		$this->group->init($group);
	}
	public function getGroup_id(){
		return $this->group->getId();
	}
	
	/**
	 * @param unknown_type $id
	 */
	public function setId($id) {
		$this->id = $id;
	}
	
	/**
	 * @param unknown_type $nickname
	 */
	public function setNickname($nickname) {
		$this->nickname = $nickname;
	}
	
	/**
	 * @param unknown_type $password
	 */
	public function setPassword($password) {
		$this->password = md5($password);
	}
	
	/**
	 * @param unknown_type $regdate
	 */
	public function setRegdate($regdate) {
		$this->regdate = $regdate;
	}
	
	/**
	 * @param unknown_type $root
	 */
	public function setRoot($root) {
		$this->root = $root;
	}
	
	/**
	 * @param unknown_type $username
	 */
	public function setUsername($username) {
		$this->username = $username;
	}
	public function Member($jieku){
		$this->jieku=$jieku;
	}
	public function init($id){
		$this->setId($id);
		$db=$this->jieku->getDB();
		$db->query(JDBTool::select("*","sys_member",array("id"=>$this->id)));
		$result=$db->next();
		$this->setEmail($result[email]);
		$this->setGroup($result[group_id]);
		$this->setId($result[id]);
		$this->setNickname($result[nickname]);
		$this->setUsername($result[username]);
		$this->password=$result[password];
		$this->setRegdate($result[regdate]);
		$this->setRoot($result[root]);
		$this->setQq($result[qq]);
	}
	public function insert(){
		$db=$this->jieku->getDB();
		$db->exec(JDBTool::insert("sys_member",array(
			'username'=>$this->getUsername(),
			'password'=>$this->getPassword(),
			'group_id'=>$this->getGroup_id(),
			'nickname'=>$this->getNickname(),
			'email'=>$this->getEmail(),
			'regdate'=>$this->getRegdate(),
			'root'=>$this->getRoot(),
			'qq'=>$this->getQq()
		)));
		$this->setId($db->insertID());
	}
	public function delete(){
		$db=$this->jieku->getDB();
		$db->exec(JDBTool::delete("sys_member",array('id'=>$this->getId())));
	}
	public function update(){
		$db=$this->jieku->getDB();
		$db->exec(JDBTool::update("sys_member",array(
			'username'=>$this->getUsername(),
			'password'=>$this->getPassword(),
			'group_id'=>$this->getGroup_id(),
			'nickname'=>$this->getNickname(),
			'email'=>$this->getEmail(),
			'regdate'=>$this->getRegdate(),
			'root'=>$this->getRoot(),
			'qq'=>$this->getQq()
		),array('id'=>$this->getId())));
	}
	public function login(){
		$db=$this->jieku->getDB();
		$db->query(JDBTool::select("*","sys_member","username='$this->username' and password='$this->password'"));
		$result=$db->next();
		$this->setId($result[id]);
		$this->setEmail($result[email]);
		$this->setGroup($result[group_id]);
		$this->setId($result[id]);
		$this->setNickname($result[nickname]);
		$this->setRegdate($result[regdate]);
		$this->setRoot($result[root]);
		$this->setQq($result[qq]);
		return $this->getId();
	}
}
?>
